package com.sky.controller.user;

import com.sky.context.BaseContext;
import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 梁科
 * @Version 1.0
 * @ Date 2025/10/28 0:29
 */
@Slf4j
@Api(tags = "C端购物车相关接口")
@RestController
@RequestMapping(value = "/user/shoppingCart")
public class ShoppingCartController {
    @Resource
    private ShoppingCartService shoppingCartService;

    /**
     * 增加购物车
     *
     * @return
     */
    @ApiOperation(value = "增加购物车")
    @PostMapping(value = "/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.add(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 查看购物车
     *
     * @return
     */
    @ApiOperation(value = "查看购物车")
    @GetMapping(value = "/list")
    public Result<List<ShoppingCart>> showShoppingCart() {
        Long userId = BaseContext.getCurrentId();
        List<ShoppingCart> shoppingCarts = shoppingCartService.showShoppingCart(userId);
        return Result.success(shoppingCarts);
    }

    /**
     * 清空购物车
     *
     * @return
     */
    @ApiOperation(value = "清空购物车")
    @DeleteMapping(value = "/clean")
    public Result cleanShoppingCart() {
        Long userId = BaseContext.getCurrentId();
        shoppingCartService.cleanShoppingCart(userId);
        return Result.success();
    }

    /**
     * 删除购物车中的某一个菜品/套餐
     *
     * @return
     */
    @ApiOperation(value = "删除购物车中的某一个菜品/套餐")
    @PostMapping(value = "/sub")
    public Result subShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.subShoppingCart(shoppingCartDTO);
        return Result.success();
    }
}
